import $axios from '../utils/request';


export const addBannerModel = (params) => {
  return $axios({
    url: `/model/addBannerModel`,
    method: 'post',
    data: { ...params }
  })
}

export const removeBannerModel = (params) => {
  return $axios({
    url: `/model/removeBannerModel`,
    method: 'post',
    data: { ...params }
  })
}
// 查询列表接口
export const getModelPage = (params) => {
  return $axios({
    url: '/model/page',
    method: 'get',
    params
  })
}

// 删除接口
export const deleteModel = (ids) => {
  return $axios({
    url: '/model',
    method: 'delete',
    params: { ids }
  })
}

// 修改接口
export const editModel = (params) => {
  return $axios({
    url: '/model',
    method: 'put',
    data: { ...params }
  })
}

// 新增接口
export const addModel = (params) => {
  return $axios({
    url: '/model',
    method: 'post',
    data: { ...params }
  })
}

// 查询详情
export const queryModelById = (id) => {
  return $axios({
    url: `/model/${id}`,
    method: 'get'
  })
}

// 获取模型分类列表
export const getCategoryList = (params) => {
  return $axios({
    url: '/category/list',
    method: 'get',
    params
  })
}

// 查模型列表的接口
export const queryModelList = (params) => {
  return $axios({
    url: '/model/listModels',
    method: 'get',
    params
  })
}
// 文件down预览
export const commonDownload = (params) => {
  return $axios({
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
    },
    url: '/common/download',
    method: 'get',
    params
  })
}

// 起售停售---批量起售停售接口
export const modelStatusByStatus = (params) => {
  return $axios({
    url: `/model/status/${params.status}`,
    method: 'post',
    params: { ids: params.id }
  })
}

// Update your axios method to handle the response
export const downloadGLBPreview = (params, onDownloadProgress) => {
  return $axios({
    url: `http://42.192.90.134:81/common/downloadGLBPreview`,
    method: 'get',
    params,
    responseType: 'blob', // Set responseType to 'blob'
    onDownloadProgress, // Pass the onDownloadProgress callback
  }).then(response => {

    // Handle the blob response
    const blob = new Blob([response.data], { type: 'model/gltf-binary' });
    const url = window.URL.createObjectURL(blob);


    return url;
  });
};

